//
//  WLFileRenameAlertView.m
//  WanLian
//
//  Created by muzhuang on 2018/11/3.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLFileRenameAlertView.h"

@implementation WLFileRenameAlertView

- (instancetype)initWithTitle:(NSString *)strTitle
{
    self = [super init];
    if (self) {
        CGFloat width = WIDTH_SCREEN_WL-WLScaleX(72);
        _alert = [[UIView alloc]initWithFrame:CGRectMake(WLScaleX(36), (HEIGHT_SCREEN_WL-WLScaleX(170))/2.0-50, width, WLScaleX(170))];
        _alert.backgroundColor = wlUIColorRGB(0xFAFAFA);
        [self addSubview:_alert];
        _alert.layer.cornerRadius = 5;
        _alert.layer.masksToBounds = YES;
        
        self.frame = [[UIScreen mainScreen]bounds];
        self.backgroundColor = wlRGBACOLOR(0, 0, 0, 0.5);
        
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, WLScaleX(24), width-10, 24)];
        titleLabel.text = strTitle;//@"绑定INT账户";
        titleLabel.textColor = wlBlackColor;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [WLCommonTool fontTypePingFangSCMedium:17];
        [_alert addSubview:titleLabel];
        
        UIView *vTextBack = [[UIView alloc] initWithFrame:CGRectMake(WLScaleX(35), WLScaleX(65), width-WLScaleX(70), WLScaleX(40))];
        vTextBack.layer.cornerRadius = 5;
        vTextBack.layer.masksToBounds = YES;
        vTextBack.layer.borderWidth = 1;
        vTextBack.layer.borderColor = wlLightTextColor.CGColor;
        [_alert addSubview:vTextBack];
        
        textAddr = [[UITextField alloc] initWithFrame:CGRectMake(WLScaleX(40), WLScaleX(65), width-WLScaleX(75), WLScaleX(40))];
        textAddr.keyboardType = UIKeyboardTypeASCIICapable;
        textAddr.font = [WLCommonTool fontTypePingFangSCRegular:14];
        textAddr.textColor = wlDarkGrayColor;
        textAddr.clearButtonMode = UITextFieldViewModeWhileEditing;
        [_alert addSubview:textAddr];
        
        UIView *henV = [[UIView alloc]initWithFrame:CGRectMake(0, WLScaleX(170-44), width, 1)];
        henV.backgroundColor = wlUIColorRGB(0xF2F2F2);
        [_alert addSubview:henV];
        
        UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, WLScaleX(170-44), width/2.0-20, WLScaleX(44))];
        cancelBtn.titleLabel.font = [WLCommonTool fontTypePingFangSCMedium:17];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn setTitleColor:wlUnderlineColor forState:UIControlStateNormal];
        [cancelBtn addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
        [_alert addSubview:cancelBtn];
        
        UIView *verticaline = [[UIView alloc]initWithFrame:CGRectMake(width/2.0, WLScaleX(170-37), 1, WLScaleX(30))];
        verticaline.backgroundColor = wlUIColorRGB(0xF2F2F2);
        [_alert addSubview:verticaline];
        
        UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(width/2.0+10, WLScaleX(170-44), width/2.0-20, WLScaleX(44))];
        sureBtn.titleLabel.font = [WLCommonTool fontTypePingFangSCMedium:17];
        [sureBtn setTitle:@"确认" forState:UIControlStateNormal];
        [sureBtn setTitleColor:wlUIColorRGB(0x29A8FA) forState:UIControlStateNormal];
        [sureBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
        [_alert addSubview:sureBtn];
    }
    return self;
}

- (void)cancelClick
{
    [self hide];
}


- (void)setOriginContent:(NSString *)content {
    if (content.length > 0) {
        textAddr.text = content;
    }
}
- (void)sureClick
{
    NSString *str = textAddr.text;
    if (str.length<1) {
        [self showHUDMessage:@"请输入正确的名称"];
    }
    else
    {
        if (self.okAction) {
            self.okAction(str);
        }
        [self hide];
//        WLWkSelf
//        NSDictionary *paramsp = @{@"intAccount":str};//SF678FHHHGYU76BNJ78
//        [WLHttpManager WLRequestMethod:RequestTypePost urlStr:@"user/modify/bindint" withParamsDic:paramsp success:^(NSDictionary *successDict) {
//            [weakSelf hide];
//            if (weakSelf.okAction) {
//                weakSelf.okAction(str);
//            }
//            WLUserInfo *user = [[WLUseManager shareUser] getUserInformation];
//            user.intAccount = str;
//            [[WLUseManager shareUser] updateUserValue:user];
//        } failure:^(NSString *errorMsg, NSInteger errorTag) {
//            [weakSelf showHUDMessage:errorMsg];
//        } error:^(NSError *error) {
//
//        } inView:self];
    }
}

- (void)show
{
    if (self.superview==nil) {
        UIWindow *window =  [[UIApplication sharedApplication].windows firstObject];
        [window addSubview:self];
    }
    
    self.alpha = 0;
    _alert.transform = CGAffineTransformScale(_alert.transform,0.1,0.1);
    WLWkSelf
    [UIView animateWithDuration:0.25 animations:^{
        weakSelf.alert.transform = CGAffineTransformIdentity;
        self.alpha = 1;
    }];
}

- (void)hide
{
    if (self.superview) {
        WLWkSelf
        [UIView animateWithDuration:0.25 animations:^{
            weakSelf.alert.transform = CGAffineTransformScale(weakSelf.alert.transform,0.1,0.1);
            self.alpha = 0;
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
